﻿
namespace SRTSolutions.Elevate
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// A concrete implementation of System.Collections.ObjectModel.KeyedCollection
    /// which takes getKeyForItem on construction.
    /// </summary>
    /// <typeparam name="TKey"></typeparam>
    /// <typeparam name="TValue"></typeparam>
    public class KeyedCollection2<TKey, TValue> : System.Collections.ObjectModel.KeyedCollection<TKey, TValue>
    {
        private readonly Func<TValue, TKey> getKeyForItem;
        /// <summary>
        /// Initializes a new instance of the KeyedCollection2 class.
        /// </summary>
        public KeyedCollection2(Func<TValue,TKey> getKeyForItem)
        {
            this.getKeyForItem = getKeyForItem;            
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        protected sealed override TKey GetKeyForItem(TValue item)
        {
            return getKeyForItem(item);
        }
    }
}
